<!-- 司机管理 - 综合表单页面 -->
<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="SuperTablePage" :cell-class-name="cellClassMethod" @selection-change="e => selection = e">

    </ex_super_table_page>
    <vehicle_listSelect ref="vehicle_listSelect" @afterSubmit="adjustingVehicle" />
  </div>
</template>
<script>
import superTablePageFunction from '@/mixin/super-table-page-function';




import vehicle_listSelect from '@/component/tms/vehicle_listSelect.vue';

import emitOnFunction from '@/mixin/emit-on-function';
let emitKey = 'tms>>driver_manage'



export default {
  title: 'label_tms_driver_driver_management',
  mixins: [superTablePageFunction, emitOnFunction(emitKey)],
  components: { vehicle_listSelect },
  data() {
    return {
      selection: [],

      option: {
        //搜索框内容
        search: {
          model: [
            { label: "label_tms_driver_driver_name", key: "driverName", },
            { label: "label_tms_driver_phone", key: "phone", },
            { label: "label_tms_driver_driver_status", key: "status", type: 'select', enum: 'IsAvailableStatusEnum', },
            {
              label: "label_create_time", key: 'startTime', type: 'date-picker', placeholder: "label_start_time", attrs: { type: 'datetime' },
              on: { change: (e) => this.startTime = e },
              'pickerOptions': {
                disabledDate: (date) => {
                  if (this.endTime) {
                    return this.endTime < date.getTime()
                  }
                  return false
                }
              }
            },
            {
              label: "~", key: 'endTime', type: 'date-picker', placeholder: "label_end_time", attrs: { type: 'datetime' },
              on: { change: (e) => this.endTime = e },
              'pickerOptions': {
                disabledDate: (date) => {
                  if (this.startTime) {
                    return this.startTime > date.getTime()
                  }
                  return false
                }
              }
            },
          ],
        },
        action: [
          {
            label: 'label_tms_driver_add_driver', attrs: { icon: "el-icon-plus" }, click: () => {
              this.clickCreate()
            }
          },
        ],
        actionExtra: [
          { label: 'label_tms_driver_driver_monitoring', click: this.$noFunction },
          { label: 'label_tms_driver_rank_setting_list', click: this.$noFunction },
          { label: 'label_tms_driver_kpi_config', click: this.$noFunction },
          { label: 'label_tms_driver_kpi_result', click: this.$noFunction },
          { label: 'label_tms_driver_expiration_reminder', click: this.$noFunction },

          { label: 'label_tms_driver_maturity_warning', click: this.$noFunction },

          { label: 'label_export', attrs: { type: "primary" }, click: this.exportExcel },
        ],
        table: {
          url: "/tms-api/base/TmsDriverInfoRpc/selectByPage.json",
          model: [
          { type: 'selection', clickToggle: true, },

            { key: 'driverName', label: 'label_tms_driver_driver_name', 'min-width': 120, 'show-overflow-tooltip': true, },
            { key: 'phone', label: 'label_tms_driver_phone_number', 'min-width': 120, 'show-overflow-tooltip': true, },
            { key: 'ownerCity', label: 'label_tms_driver_home_city', 'width': 120, 'show-overflow-tooltip': true, },
            { key: 'supplierName', label: 'label_tms_driver_affiliated_supplier', 'width': 120, 'show-overflow-tooltip': true, },
            { key: 'driverLicenseType', label: 'label_tms_driver_license', 'width': 80, },
            { key: 'drivingExperience', label: 'label_tms_driver_driving_years', 'width': 80, },
            { key: 'drivingHours', label: 'label_tms_driver_duration', 'width': 80, },
            { key: 'vehicleTypeName', label: 'label_tms_driver_regular_driving_type', 'width': 80, },
            { key: 'vehicleNo', label: 'label_tms_driver_Regular_license', 'width': 120, 'show-overflow-tooltip': true, },
            { key: 'status', label: 'label_tms_driver_driver_status', 'width': 100, formatter: (r, c, v, i) => this.$enumShow(v, "IsAvailableStatusEnum") },
            { key: 'isWarning', label: 'label_tms_driver_warning_setting', 'width': 100, },
            { key: 'stopReason', label: 'label_tms_driver_stop_reason', 'width': 100, },
            { key: 'creator', label: 'label_create_user', 'width': 100, },
            { key: 'gmtCreate', label: 'label_create_time', 'width': 130, formatter: (r, c, v, i) => this.$dateFormat(v) },
            {
              type: 'operate', width: 170, operate: [
                {
                  label: 'label_edit', click: (row) => {
                    this.clickEdit(row)
                  }
                },
                {
                  label: 'label_start_using', type: "confirm-button", url: '/tms-api/base/TmsDriverInfoRpc/enableOrDisable.json', message: 'label_sure_to_enable_this',
                  buttonClass: "button_text_success", confirmButtonType: 'success',
                  if: (row) => row.status == 'DISABLED',
                  params: (row) => {
                    return { id: row["id"], status: 'ENABLE' }
                  }, done: ['tip', 'reload']
                },
                {
                  label: 'label_disable_using', type: "confirm-button", url: '/tms-api/base/TmsDriverInfoRpc/enableOrDisable.json', message: 'label_tms_confirm_stop',
                  buttonClass: "button_text_danger", confirmButtonType: 'danger',
                  if: (row) => row.status == 'ENABLE',
                  params: (row) => {
                    return { id: row["id"], status: 'DISABLED' }
                  }, done: ['tip', 'reload']
                },
                {
                  type: 'more',
                  items: [
                    { label: 'label_view_detail', click: (row) => { this.$noFunction(row) } },
                    {
                      label: 'label_tms_driver_vehicle_adjust',
                      click: (row) => this.$refs.vehicle_listSelect.show({ title: "label_tms_driver_vehicle_adjust", extraData: row })
                    },
                  ]
                }
              ],
            }
          ],
        }
        ,

      },


    };
  },
  methods: {
    cellClassMethod({ row, column, rowIndex, columnIndex }) {
      if (column.property == 'status') {
        if (row.status == 'ENABLE') {
          return 'color_success'
        } else if (row.status == 'DISABLED') {
          return 'color_danger'
        }
      }
      return ""
    },
    clickCreate() {
      this.$router.push({ path: '/page/tms/base/driver_operate', query: { emitKey } })
    },
    clickEdit(row) {
      this.$router.push({ path: '/page/tms/base/driver_operate', query: { id: row.id, emitKey, edit: true, } })
    },
    adjustingVehicle({ select, extraData }) {
      this.$ajax({
        url: "/tms-api/base/TmsVehicleInfoRpc/adjustingVehicle.json",
        method: 'post',
        data: {
          id: select.id, driverId: extraData.id,
        },
        success: (res) => {
          this.$refs.vehicle_listSelect.hide()
          this.reload()
        }
      })
    },
    exportExcel() {
      this.$downloadFile({
        loading: true,
        type: 'json',
        url: '/tms-api/base/TmsDriverInfoRpc/exportExcel.json',
        data: {
          driverIds: this.selection.map(it => it.id),
          ...this.getSuperTablePage().getSearchFormData()
        },
      })
    },
  }
};

</script>
<style></style>
